<!--
 * @name: 
 * @version: 1.1.1
 * @Author: 刘大可
 * @Date: 2022-10-26 18:15:22
 * @LastEditors: 刘大可
 * @LastEditTime: 2023-10-20 14:44:14
-->
<template>
    <view  >
        <view class="headers" :style="{'margin-top':'-'+top+'px','padding-top':top+'px'}">
            <view class="search row" @click="go('/gc_school/pages/canteen/list')">
                店铺名称/美食名称
                <view class="cuIcon-search"></view>
            </view>
            <swiper class="banner margin-lr" :class="rank_show?'':'margin-top'" :autoplay="true" :current="current"
                v-if="schoolInfo.slide.length>0">
                <block v-if="schoolInfo.slide.length > 0">
                    <block v-for="(item, index) in schoolInfo.slide" :key="index">
                        <swiper-item>
                            <block v-if="item.img">
                                <image :src="item.img" mode="widthFix" @tap="slideJump" :data-url="item.url"
                                    :data-type="item.url_type"></image>
                            </block>
                            <block v-else>
                                <image src="/static/images/banners.jpg" mode="widthFix"></image>
                            </block>
                        </swiper-item>
                    </block>
                </block>
                <block v-else>
                    <swiper-item>
                        <image src="/static/images/banners.jpg" mode="widthFix"></image>
                    </swiper-item>
                </block>
            </swiper>
        </view>
        <view class="tipss margin-top-xs row" v-if="schoolInfo.notice">
            <image
                class="laba"
                src="https://zanmao-oss.oss-cn-shanghai.aliyuncs.com/site/gonggao.png"
                mode="aspectFit"
            />
            <uni-notice-bar @click="go('/gc_school/pages/notice/notice?id='+schoolInfo.notice[0].id)" background-color="#fff"
                color="#000" v-if="schoolInfo.notice.length>0" class="margin-lr tips"  scrollable
                :text="schoolInfo.notice[0].title" 
                
                moreText	="查看更多"
    						moreColor="#111"
    						:showGetMore="schoolInfo.notice.length > 1"
    						@getmore.stop="goAllNotice(schoolInfo.notice)"
                
                
                
                />
        </view>

        <view class="navs margin-tb-xs padding-bottom" style="margin-top:10rpx; background-color:#fff;margin:10rpx 30rpx;     border-radius: 16rpx;">
            <!-- {{ schoolInfo.modules.length }} -->
            <school-nav-bar :navlist="schoolInfo.modules"></school-nav-bar>
            <!-- <school-store-classify></school-store-classify> -->
        </view>
        
        <view class="hart_store" v-if="hart.length>0">
            <view class="tit row">
                <view class="cuIcon-hotfill cuIcon"></view>
                点餐热榜
                <view class="sub_tit">
                    | 看看他们在吃什么
                </view>
            </view>
            <view class="hart_list row">
                <block v-for="(item,index) in hart" :key="index">
                    <view class="hart_item"  @click="goStore('/gc_school/pages/foold/foold?id=' + item.business_id)">
                        <image
                            class="main_img"
                            :src="item.goods.goods_img"
                            mode="scaleToFill"
                        />
                        <view class="title">{{item.goods.goods_name}}</view>
                    </view>
                
                </block>
            </view>
        </view>
        <view class="topp" :style="{'top':top+'px'}">

            <view class="cates row">
                <block v-for="(item,index) in list" :key="index">
                    <view class="cate col" :class="flg==index?'cur':''" @click="tagetCate(item.type_id,index)">
                        {{item.type_name}}
                        <!-- {{item.type_id}} -->
                    </view>
                </block>
            </view>
        </view>
        <view class="store_list">
            <block v-for="(item,index) in  goods" :key="index">
                <view class="store_item"   @click="goStore('/gc_school/pages/foold/foold?id=' + item.business_id)">
                    <view class="store_info row">
                        <image
                            class="main_img"
                            :src="item.business_image"
                            mode="scaleToFill"
                            
                        />
                        <view class="info">
                            <view class="name row">
                               {{item.business_name}}
                                <view class="tag row tag2" v-if="item.is_dormitory_store==1">
                                  宿舍小店
                                </view>
                                <view class="tag row" :class="item.type != 1?'tag1':'tag2'" v-else>
                                    {{item.type != 1? "校外":"校内"}}
                                </view>
                            </view>
                            <view class="date">营业时间：{{item.timeslot}}</view>
                            <view class="date">已售{{item.sale_num}}份 ¥{{item.starting_fee }}起送</view>
                            <school-coupon-tag :coupon_list="item.coupon_list"></school-coupon-tag>
                        </view>
                    </view>
                    <view class="goods_list row" v-if="item.goods.length>0">
                        <block v-for="(gitem,gindex) in item.goods" :key="gindex">
                            <view class="goods_item">
                                <image class="main_img" :src="gitem.goods_img" mode="scaleToFill" />
                                <view class="title">{{gitem.goods_name}}</view>
                                <view class="price">￥{{gitem.price}}</view>
                            </view>
                        
                        </block>
                        
                    </view>
                </view>
            </block>
            <view class="all col" @click="nextPage"  v-if="content=='查看更多'">
                {{ content }}
            </view>
        </view>

       
    </view>
</template>
<script>
var app = getApp();
export default {
    data() {
        return {
            list:[],
            flg:0,
            hart:[],
            page:1,
            goods:[],
            content:"查看更多"
        }
    },
    props: {
       top: {
            type: String,
            default() {
                return "";
            }
        },
        schoolInfo:{
            type:Object,
            default() {
                return {
                    
                };
            }
        }

    },
    created(){
        this.initData()
        try {
            
        } catch (error) {
            
        }
        this.getHart()
    },
    methods: {
         goAllNotice(noticeList = []) {
            uni.setStorageSync('noticeList', noticeList)
            this.go("/gc_school/pages/notice/list")
        },
        goStore(e) {
            // try {
            //     uni.setStorageSync('module_id', this.schoolInfo.default_store_module.id)
            // } catch (error) {

            // }
            this.go(e)
        },
        tagetCate(type_id, index){
            this.flg=index
            this.page=1
            this.getStore(type_id)

        },
        async initData() {
            var that = this;
            var shcool_id = uni.getStorageSync('schoolId');
            app.globalData.util.request({
                url: 'ZhBusinesType/index',
                method: 'GET',
                data: {
                    s_id: shcool_id,
                   
                },
                success(res) {
                    if (res.data.status == 200) {
                        that.list = [
                            { "type_id": "", "s_id": "", "wxapp_id": "3", "type_name": "推荐商家", "createtime": "1648439550", "type_image": "https:\/\/test.fkynet.net\/uploads\/subschool\/202210\/635fa7ca909c0.png", "sort": "5", "type": "0" }, 

                            ...res.data.data.list,
                        ]
                        console.log(that.list);
                        if (res.data.data.list.length > 0) {
                        }
                            that.getStore();

                        console.log(that.list);
                    }
                }
            });

        },
        
        getHart(){
            var that = this;
            var shcool_id = uni.getStorageSync('schoolId');
            app.globalData.util.request({
                url: 'ZhGoodss/getcommodity',
                method: 'GET',
                data: {
                    s_id: shcool_id,
                    // page: 1,
                    // limit:10,
                },
                success(res) {
                    console.log(res);
                    if (res.data.status == 200) {
                        that.hart = [
                            ...res.data.data
                        ]
                        // if (res.data.data.list.length > 0) {
                        //     // that.getStore();
                        // }
                        // that.getStore("")
                        console.log(that.hart);
                    }
                }
            });


            // /api/?wxapp_id=3&s_id=8
        },
        nextPage(){
            this.page+=1
            let type_id = this.list[this.flg].type_id
            this.getStore(type_id)

        },
        async getStore(type_id = "") {
            var that = this;
            uni.showLoading({
                title: '加载中'
            });

            app.globalData.util.request({
                url: 'ZhBusinesType/getBusiness',
                method: 'GET',
                data: {
                    latitude: uni.getStorageSync('latitude')||0,
                    longitude: uni.getStorageSync('longitude')||0,
                    type_id: type_id,
                    page: that.page,
                    s_id: uni.getStorageSync('schoolId'),
                    kwd: "",
                    limit: 10
                },

                success:(res)=> {
                    uni.hideLoading();
                    if (res.data.status == 200) {
                        // if (res.data.data.data.length) {
                            this.goods = this.page == 1 ? res.data.data.data||[] : [
                                ...this.goods,
                                ...res.data.data.data
                            ]

                            if (res.data.data.data.length==0) {
                                this.content="没有更多了"
                            }
                            // return
                        // }
                        
                        // if (this.page>1) {
                        //     this.content = "没有更多了~"
                        //     this.tips.tips(this.content)
                        // }

                    }
                }
            });
        },

        async slideJump(e) {
            console.log(e);

            if (e.currentTarget.dataset.type == 1) {
                uni.navigateTo({
                    url: e.currentTarget.dataset.url
                });
            } else {
                if (e.currentTarget.dataset.type == 2) {
                    console.log('appid是', e.currentTarget.dataset.url);
                    let appId = e.currentTarget.dataset.url
                    // let path = e.currentTarget.dataset.url.split(';')[1]
                    uni.navigateToMiniProgram({
                        appId,
                        path: "",
                        extraData: {
                            foo: 'bar'
                        },
                        envVersion: 'release',

                        success(res) {
                            console.log('打开成功');
                        }
                    });
                } else if (e.currentTarget.dataset.type == 3) {
                    let isCourse = e.currentTarget.dataset.url.indexOf('gc-curriculum')
                    console.log(e.currentTarget.dataset.url);
                    console.log(isCourse);
                    if (isCourse > -1) {
                        await this.dingyueKeBiao()

                    }
                    uni.navigateTo({
                        url: '/gc_school/pages/webview/index?url=' + encodeURIComponent(e.currentTarget.dataset.url)
                    });
                }
            }
        },
    },
}
</script>
<style lang="scss">
    @import "./main.scss";
</style>